/*
 * @Author: 溜溜的陈 525767273@qq.com
 * @Date: 2024-12-26 17:21:30
 * @LastEditors: 溜溜的陈 525767273@qq.com
 * @LastEditTime: 2024-12-26 17:48:42
 * @FilePath: \express-serve\middleware\urlencoded.js
 * @Description:处理application/x-www-form-urlencoded类型的数据，例如：userName=123&userPwd=123
 */
const querystring = require('node:querystring')
module.exports = () => {
    // 闭包
    return () => {
        const resualt = [];
        app.use((req, res, next) => {
            if (req.header('Content-Type') !== 'application/x-www-form-urlencoded') {
                return next()
            }
            req.on('data', (chunk) => { resualt.push(chunk) })
            req.on('end', () => {
                const data = Buffer.concat(resualt).toString()
                req.body = querystring.parse(data)
                next()
            })
        })
    }
}